<?php
session_start();
include "connect.php";
$score = $_POST['score'];
$answers = $_POST['answers'].$_POST['choice'];
if($_POST['answer']==$_POST['choice']){
$score = $_POST['score']+1;
}
if($_REQUEST['q']>10){
$date_taken = date('m/d/Y');
$ID = $_SESSION['id'];
print "Thank you!<br/>";
$usernew="update users set scores='$score', answers='$answers', date_taken='$date_taken' where id=$ID;";
		mysql_query($usernew) or die(mysql_error());
		print "Your Exam was recorded";
		session_destroy();
}
	if (empty($_SESSION['user'])) {
		echo "Unknown users";
	}else{
		if(isset($_REQUEST['q'])){
			$q_num = $_REQUEST['q'];
			$result = mysql_query("select * from questionnaires where question_num = $q_num;");
			if(mysql_num_rows($result)){
				while ($row = mysql_fetch_array($result)){
						$next = $row[question_num] + 1;
						print "<form action='exam.php' method = 'post'>";
						print $row[question_num].". ".$row[question]."<br/>";
						print "<input type='radio' value='a' name='choice'>A. $row[choice_a]<br/>";
						print "<input type='radio' value='b' name='choice'>B. $row[choice_b]<br/>";
						print "<input type='radio' value='c' name='choice'>C. $row[choice_c]<br/>";
						print "<input type='radio' value='d' name='choice'>D. $row[choice_d]<br/>";
						print "<input type='hidden' value='$row[answer]' name='answer'>";
						print "<input type='hidden' value='$score' name='score'>";
						print "<input type='hidden' value='$next' name='q'>";
						print "<input type='hidden' value='$answers' name='answers'>";
						print "<input type='submit' value='answer'>";
				}
			}
		}else{
		print "No Question Found!";
		}
	}

?>